
#import "SettingScreen.h"
#import "MainScreen.h"

@implementation SettingScreen

- (void) dealloc {
	CCLOG(@"%@: %@", NSStringFromSelector(_cmd), self);
	
	[super dealloc];
}

-(id) init {
	if ((self = [super init])) {
		
		CCLOG(@"%@: %@", NSStringFromSelector(_cmd), self);
	
		/// 标题 : 音效
		[CCMenuItemFont setFontName:@"American Typewriter"];
		[CCMenuItemFont setFontSize:18];
		CCMenuItemFont *a_p_cls_menu_title_sound = [CCMenuItemFont itemFromString: @"音效"];
		[a_p_cls_menu_title_sound setIsEnabled:NO];// 用一个禁止状态的菜单项作为标题
		/// 音效 设置开关
		[CCMenuItemFont setFontName: @"Marker Felt"];
		[CCMenuItemFont setFontSize:26];
		CCMenuItemToggle *a_p_cls_menu_item_sound = [CCMenuItemToggle itemWithTarget:self 
																																			selector:@selector(SettingScreen_menuClickCallback:) 
																											                   items:[CCMenuItemFont itemFromString: @"开"],
														                                                   [CCMenuItemFont itemFromString: @"关"],
														                                                    nil];
		/// 标题 : 音乐
		[CCMenuItemFont setFontName: @"American Typewriter"];
		[CCMenuItemFont setFontSize:18];
		CCMenuItemFont *a_p_cls_menu_title_music = [CCMenuItemFont itemFromString: @"音乐"];
		[a_p_cls_menu_title_music setIsEnabled:NO];
		/// 音乐 设置开关
		[CCMenuItemFont setFontName: @"Marker Felt"];
		[CCMenuItemFont setFontSize:26];
		CCMenuItemToggle *a_p_cls_menu_item_music = [CCMenuItemToggle itemWithTarget:self 
																																			selector:@selector(SettingScreen_menuClickCallback:) 
																																				 items:[CCMenuItemFont itemFromString: @"开"],
                                                                               [CCMenuItemFont itemFromString: @"关"],
                                                                                nil];
	
		/// 标题 : 难度
		[CCMenuItemFont setFontName: @"American Typewriter"];
		[CCMenuItemFont setFontSize:18];
		CCMenuItemFont *a_p_cls_menu_title_difficulty = [CCMenuItemFont itemFromString: @"难度"];
		[a_p_cls_menu_title_difficulty setIsEnabled:NO];
		/// 游戏难度 设置开关
		[CCMenuItemFont setFontName: @"Marker Felt"];
		[CCMenuItemFont setFontSize:26];
		CCMenuItemToggle *a_p_cls_menu_item_difficulty = [CCMenuItemToggle itemWithTarget:self 
																																			     selector:@selector(SettingScreen_menuClickCallback:) 
																																				      items:[CCMenuItemFont itemFromString: @"简单"],
																							                                      [CCMenuItemFont itemFromString: @"正常"],
																																										[CCMenuItemFont itemFromString: @"困难"],
																							                                       nil];
	
	
		[CCMenuItemFont setFontName: @"Marker Felt"];
		[CCMenuItemFont setFontSize:26];
	

		/// 返回按钮, 使用 位图字体
		CCLabelBMFont *a_p_cls_go_back_label = [CCLabelBMFont labelWithString:@"Go back" fntFile:@"font01.fnt"];
	 
		CCMenuItemLabel *a_p_cls_menu_go_back = [CCMenuItemLabel itemWithLabel:a_p_cls_go_back_label 
																									                target:self 
																																selector:@selector(SettingScreen_backClickCallback:)];
		//a_p_cls_menu_go_back.scale = 1.5;
	
	
		// 组成菜单局
		CCMenu *a_p_cls_menu_list = [CCMenu menuWithItems:
                  a_p_cls_menu_title_sound, a_p_cls_menu_item_sound, 
									a_p_cls_menu_title_music, a_p_cls_menu_item_music,
                  a_p_cls_menu_title_difficulty, a_p_cls_menu_item_difficulty,
									
									a_p_cls_menu_go_back,
									nil];  
		/// 垂直排成一排
		[a_p_cls_menu_list alignItemsInColumns:
		[NSNumber numberWithUnsignedInt:2],
		[NSNumber numberWithUnsignedInt:2],
		[NSNumber numberWithUnsignedInt:2],
		[NSNumber numberWithUnsignedInt:1],
	 
		nil
		];  
	
		/// 要想手动修改 菜单控件的坐标, 必须在布局动作完成后(alignItemsInColumns 布局动作)
		a_p_cls_menu_go_back.position = 
			ccp(a_p_cls_menu_go_back.contentSize.width - [[CCDirector sharedDirector] winSize].width / 2, 
					a_p_cls_menu_go_back.contentSize.height - [[CCDirector sharedDirector] winSize].height / 2);
	
		/// 
		[self addChild: a_p_cls_menu_list];
	
	}
	
	return self;
}

/**
 * @brief 点击 设置菜单按钮后触发的处理回调函数
 *
 * @param[in] (id) sender
 * @param[out] nil
 *
 * @return void
 *
 * @note注解
 *
 */
-(void) SettingScreen_menuClickCallback: (id) sender{
	NSLog(@"selected item: %@ index:%d", [sender selectedItem], [sender selectedIndex] );
}

/**
 * @brief 点击了 返回主菜单 按钮 
 *
 * @param[in] (id) sender
 * @param[out] nil
 *
 * @return void
 *
 * @note注解
 *
 */
-(void) SettingScreen_backClickCallback: (id) sender {
	CCScene *a_p_cls_main_screen_scene = [CCScene node];
	[a_p_cls_main_screen_scene addChild:[MainScreen node]];
	
	[[CCDirector sharedDirector] replaceScene:[CCTransitionSlideInL transitionWithDuration:1.2f 
																																									 scene:a_p_cls_main_screen_scene]];	
}

@end
